﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XCI.Windows.Forms;
using XCI.Windows.Helper;

namespace XCI.Sys.Forms
{
    public partial class FrmUserSetting : FrmBase
    {
        public FrmUserSetting()
        {
            InitializeComponent();
        }

        private void FillPageSizeList()
        {
            var sz = editPageSizeList.Text.Trim().Split(',');
            comboBoxPageSize.Properties.Items.Clear();
            comboBoxPageSize.Properties.Items.BeginUpdate();
            foreach (var item in sz)
            {
                comboBoxPageSize.Properties.Items.Add(item);
            }
            comboBoxPageSize.Properties.Items.EndUpdate();
        }

        private void FrmUserSetting_Load(object sender, EventArgs e)
        {
            WinHelper.SetFormData(panel1, SysRuntime.Setting);
            FillPageSizeList();
            if (SysRuntime.Setting.CloseMainIsExit)
            {
                CheckEdit8.Checked = true;
            }
            else
            {
                CheckEdit7.Checked = true;
            }
        }

        private void BtnOk_Click(object sender, EventArgs e)
        {
            WinHelper.GetFormData(panel1, SysRuntime.Setting);
            SysRuntime.Setting.CloseMainIsExit = CheckEdit8.Checked;
            SysRuntime.Setting.ShowNotification = CheckEdit7.Checked;
            SysRuntime.App.SaveSetting(SysRuntime.Setting);
            MessageBoxHelper.ShowMessage("保存成功,部分参数重启后生效");
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void BtnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void EditAllowAutoLockMain_CheckedChanged(object sender, EventArgs e)
        {
            editAutoLockInterval.Enabled = editAllowAutoLockMain.Checked;
        }

        private void EditPageSizeList_EditValueChanged(object sender, EventArgs e)
        {
            FillPageSizeList();
        }
    }
}
